package com.etoak.car.controller;


import com.etoak.car.service.LikeService;
import com.etoak.commons.enums.ETEnums;
import com.etoak.commons.response.ETResponse;
import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("/like")
public class LikeController {

    @Autowired
    LikeService likeService;



    public static final String LIKE_PIC_KEY_PREFIX = "PIC:100";

    @GetMapping("/{userid}")
    public ETResponse like(@PathVariable Integer userid){
       // String key = LIKE_PIC_KEY_PREFIX + picId;
        //return likeServiceHash.like(key,username);
        Map<String, Object> like = likeService.like(LIKE_PIC_KEY_PREFIX, userid + "");
        ETResponse response = new ETResponse();
        response.setCode(ETEnums.SUCCESS.getCode());
        response.setMsg(ETEnums.SUCCESS.getMsg());
        response.setData(like);
        return response;


    }
    @PostMapping("/{key}")
    public ETResponse queryLike(@PathVariable String key){
        // String key = LIKE_PIC_KEY_PREFIX + picId;
        //return likeServiceHash.like(key,username);
        long likeCount = likeService.getLikeCount(key);
        ETResponse response = new ETResponse();
        response.setCode(ETEnums.SUCCESS.getCode());
        response.setMsg(ETEnums.SUCCESS.getMsg());
        response.setData(likeCount);
        return response;


    }
    /*@RequestMapping("/{picId}")
    public Object getUsers(@PathVariable String picId){
        String key = LIKE_PIC_KEY_PREFIX + picId;
        //return likeServiceHash.getLikeUser(key);
        return likeService.getLikeUser(key);

    }*/

    /*@RequestMapping("/user/{picId}")
    public Object getLikeUsers(@PathVariable String picId){
        String key = LIKE_PIC_KEY_PREFIX + picId;
        return likeServiceSet.getLikeUser(key);
    }*/

}
